<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>龙湖社区管理系统登录</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <!--引入本地的css样式-->
  <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="static/css/admin.css" media="all">
  <link rel="stylesheet" href="static/css/login.css" media="all">

</head>
<!--009688-->
<body style="background:url('static/images/background2.svg');">

  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main" style="background-color: white;">
    <!--页眉-->
      <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2 style="color:#029789;">龙湖社区管理系统</h2>
            <p>小区管理设计规范</p>
      </div>
    <!--主体-->
      <form class="layadmin-user-login-box layadmin-user-login-body layui-form" action="" style="padding: 20px;">
           <!--用户名-->
           <div class="layui-form-item">
               <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
               <input type="text" name="username" id="LAY-user-login-username" lay-verify="required|username" placeholder="用户名" class="layui-input">
           </div>
           <!--密码-->
          <div class="layui-form-item">
              <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
              <input type="password" name="password" id="LAY-user-login-password" lay-verify="required|password" placeholder="密码" class="layui-input">
          </div>
          <!--验证码：一行两部分 栅格系统-->
          <div class="layui-form-item">
                <!--定义行-->
                <div class="layui-row">
                    <!--定义列-->
                    <!--输入验证码输入框-->
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                        <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required|vercode" placeholder="图形验证码" class="layui-input">
                    </div>
                    <!--验证码显示-->
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px">
                            <img class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">
                        </div>
                    </div>
                </div>
          </div>
          <div class="layui-form-item" style="margin-bottom: 20px;">
          <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
          <a href="forget.html" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
          </div>
          <!--提交按钮-->
          <div class="layui-form-item">
              <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo1">登录</button>
          </div>
      </form>
    </div>

    <!--页尾/脚-->
    <div class="layui-trans layadmin-user-login-footer">
      <p><i class="layui-icon layui-icon-login-wechat"></i>微信登录</p>
    </div>

    
  </div>

  <!--导入Jquery才可以使用AJax-->
  <script src="static/js/jquery-3.6.0.min.js"></script>
  <!--引入本地layui.js-->
  <script src="static/layui/layui.js"></script>
  <script type="text/javascript">
<!--    获取验证码-->
    $.get('/captcha',function (res){//res响应回来的数据
        $("#LAY-user-get-vercode").attr("src",res.image)//设置验证码图片
    },"json")
    $("#LAY-user-get-vercode").click(function(){
        $.get('/captcha',function (res){//res响应回来的数据
            $("#LAY-user-get-vercode").attr("src",res.image)//设置验证码图片
        },"json")
    })
  </script>
  <script type="text/javascript">
<!--      引入layer和form-->
    layui.use(["layer","form"],function (){
        var layer = layui.layer;
        var form = layui.form;
        // 自定义验证规则
        form.verify({
            username:function (value){
                if(value.length<3){
                    return "用户名至少为3个字符"
                }
            },
            password:function (value){
                if(value.length<6||value.length>12){
                    return "密码长度应在6~12位"
                }
            },
            vercode:function (value){
                if(value.length==0){
                    return "请输入验证码"
                }
            }
        })
        // 监听登录按钮，ajax异步请求登录
        form.on('submit(demo1)',function (data) {
            // 发起ajax异步请求
            $.ajax({
                url:"/login",
                type:"GET",
                data:data.field,
                dataType:"json",
                success:function (res){//响应的数据
                    console.log(res)
                    if(res.code == 200){
                        layer.msg("登录成功",{
                            offset:'15px',
                            icon:1,
                            time:1000
                        },function () {
                            //取出user对象
                            var user = res.data;
                            // console.log(user);
                            //将登录信息存到sessionStorage中
                            sessionStorage.setItem("user",JSON.stringify(user));
                            // console.log(sessionStorage.getItem("user"));
                            //跳转到首页
                            window.location.href = "views/index.html";
                        })
                    }else if(res.code == 401){
                        alert(res.msg)
                    }else if(res.code == 500){
                        alert(res.msg)
                    }else {
                        alert(res.msg)
                    }
                }
            })
            return false;
        })
    })
  </script>


</body>
</html>